package com.example.agriculturemachine.ui.fragment;

import android.graphics.Rect;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.agriculturemachine.R;
import com.example.agriculturemachine.base.BaseFragment;
import com.example.agriculturemachine.bean.Datas;
import com.example.agriculturemachine.bean.ItemBean;
import com.example.agriculturemachine.ui.activity.MainActivity;
import com.example.agriculturemachine.ui.adapter.selectAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class selectFragment extends BaseFragment {
    @BindView(R.id.recycler_view)
    public RecyclerView mlist;
    private selectAdapter mrecyclerViewAdapter;
    private List<ItemBean> mdata;
//    @BindView(R.id.car_manager)
//    public Menu car_manager;
    @Override
    protected View loadRootView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_select,container,false);
    }

    @Override
    protected void initView() {
        initData();
        showList(true,false);

//      car_manager.setGroupEnabled();
    }

    private void showList(boolean isVertical, boolean isReverse) {
        LinearLayoutManager layoutManager=new LinearLayoutManager(getContext());
        layoutManager.setOrientation(isVertical? LinearLayoutManager.VERTICAL:LinearLayoutManager.HORIZONTAL);
        layoutManager.setReverseLayout(isReverse);
        mlist.setLayoutManager(layoutManager);
        mrecyclerViewAdapter = new selectAdapter(mdata);
        mrecyclerViewAdapter.setOnClickEvent(new selectAdapter.onClickEvent() {
            @Override
            public void onClickCarDetails() {
                ((MainActivity)getActivity()).switchFragment(new managerFragment());
            }
        });
        mlist.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(@NonNull Rect outRect, @NonNull  View view, @NonNull  RecyclerView parent, @NonNull  RecyclerView.State state) {
                outRect.top=20;
                outRect.bottom=20;
                outRect.left=5;
                outRect.right=5;
            }
        });
        mlist.setAdapter(mrecyclerViewAdapter);

    }

    private void initData() {
        mdata = new ArrayList<>();
        for (int i = 0; i<Datas.status.length ; i++) {
            ItemBean data=new ItemBean();
            data.status=Datas.status[i];
            data.title=Datas.title[i];
            data.binding=Datas.binding[i];
            mdata.add(data);
        }
    }

}
